<?php
session_start();

if (empty($_SESSION['username'])) {
    echo '<script type="text/javascript">window.location.href="index.php";</script>';
} else {
    $now = time();
    if ($now > $_SESSION['expire']) {
        session_destroy();
        echo '<script type="text/javascript">var r=confirm("Session expire (30 mins)!"); if(r==true){window.location.href="index.php";}else{window.location.href="index.php";}</script>';
    }
}
?>

<!DOCTYPE html>
<!--[if lt IE 7]> <html class="ie lt-ie9 lt-ie8 lt-ie7 sidebar sidebar-discover"> <![endif]-->
<!--[if IE 7]>    <html class="ie lt-ie9 lt-ie8 sidebar sidebar-discover"> <![endif]-->
<!--[if IE 8]>    <html class="ie lt-ie9 sidebar sidebar-discover"> <![endif]-->
<!--[if gt IE 8]> <html class="ie sidebar sidebar-discover"> <![endif]-->
<!--[if !IE]><!--><html class="sidebar sidebar-discover"><!-- <![endif]-->
    <head>
        <title>Out Source Building Management</title>

        <!-- Meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">


        <!-- 
        **********************************************************
        In development, use the LESS files and the less.js compiler
        instead of the minified CSS loaded by default.
        **********************************************************
        <link rel="stylesheet/less" href="assets/less/admin/module.admin.stylesheet-complete.less" />
        -->

        <!--[if lt IE 9]><link rel="stylesheet" href="assets/components/library/bootstrap/css/bootstrap.min.css" /><![endif]-->
        <link rel="stylesheet" href="assets/css/admin/module.admin.stylesheet-complete.min.css" />

        <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
        <!--[if lt IE 9]>
          <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
          <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
        <![endif]-->


        <script src="assets/components/library/jquery/jquery.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/library/jquery/jquery-migrate.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/library/modernizr/modernizr.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/plugins/less-js/less.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/modules/admin/charts/flot/assets/lib/excanvas.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/plugins/browser/ie/ie.prototype.polyfill.js?v=v1.0.2&sv=v0.0.1"></script>	<script>if (/*@cc_on!@*/false && document.documentMode === 10) {
                document.documentElement.className += ' ie ie10';
            }</script>

    </head>
    <body class="">

        <!-- Main Container Fluid -->
        <div class="container-fluid menu-hidden" style="visibility: visible;">
            <!-- Content -->
            <div id="content">

                <div class="navbar hidden-print main" role="navigation" >

                    <ul class="main pull-left hidden-xs">
                        <li class="dropdown">
                            <a data-toggle="dropdown" class="dropdown-toggle" href="">Main Menu<span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li><a href="index-mainpage.php">Main Page (หน้าหลัก)</a></li>
                                <li><a href="#" class="link-project">Projects (โครงการ)</a></li>
                                <li><a href="#" class="link-team-builder">Builder (ทีมช่าง)</a></li>
                                <li><a href="typography.html?lang=en">Task Assignment (มอบหมายงาน)</a></li>
                                <li><a href="#" class="link-po-inspection">PO/Inspection (PO/ใบตรวจรับงาน)</a></li>
                                <li><a href="sliders.html?lang=en">Billing (PO/PR/ใบเสร็จ)</a></li>
                                <li><a href="sliders.html?lang=en">Search/Report (ค้นหา/รายงาน)</a></li>

                            </ul>
                        </li>
                    </ul>


                    <ul class="main pull-right">
                        <li class="dropdown username">
                            <a href="" class="dropdown-toggle" data-toggle="dropdown"><?= $_SESSION['username'] ?> <span class="caret"></span></a>

                            <ul class="dropdown-menu pull-right">
                                <li><a href="#" class="glyphicons user" id="load-account-page"><i></i> Account</a></li>
                                <?php
                                if ($_SESSION['permission_id'] == "999999") {
                                    echo '<li><a href="#" class="glyphicons notes_2" id="load-account-page"><i></i>Data Configuration</a></li>';
                                }
                                ?>
                                <li><a href="#" class="glyphicons lock no-ajaxify" id="logout-to"><i></i>Logout</a></li>
                            </ul>
                        </li>
                    </ul>
                </div>
                <!-- // END navbar -->



                <div class="innerLR" id="test-load">
                    <div class="separator-h"></div>
                    <!-- Row -->							
                    <div class="row">


                        <!-- Col -->
                        <div class="col-md-10" >

                            <!-- Start Featured -->
                            <div class="row">
                                <div class="col-sm-3">
                                    <div class="widget">
                                        <a href="#" class="display-block bg-success innerAll text-center text-white link-project"><i class="icon-projector-screen-bar fa-5x"></i></a>
                                        <div class="text-center innerAll">
                                            <a href="#" class="strong link-project">Project</a>
                                            <div class="clearfix"></div>
                                            <small class="text-center">(โครงการ)</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="widget">
                                        <a href="#" class="display-block bg-lightred innerAll text-center text-white link-team-builder"><i class="icon-group fa-5x"></i></a>
                                        <div class="text-center innerAll">
                                            <a href="#" class="strong link-team-builder">Builder</a>
                                            <div class="clearfix"></div>
                                            <small class="text-center">(ทีมช่าง)</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="widget">
                                        <a href="#" class="display-block bg-mustard innerAll text-center text-white"><i class="icon-task-check fa-5x"></i></a>
                                        <div class="text-center innerAll">
                                            <a href="" class="strong  ">Task Assignment</a>
                                            <div class="clearfix"></div>
                                            <small class="text-center">(มอบหมายงาน)</small>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-sm-3 ">
                                    <div class="widget">
                                        <a href="#" class="display-block bg-gray border-bottom innerAll text-center link-po-inspection"><i class="icon-documents-check fa-5x"></i></a>
                                        <div class="text-center innerAll">
                                            <a href="#" class="strong link-po-inspection">PO/Inspection</a>
                                            <div class="clearfix"></div>
                                            <small class="text-center">(PO/ใบตรวจรับงาน)</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="widget">
                                        <a href="#" class="display-block bg-primary innerAll text-center text-white"><i class="icon-check fa-5x"></i></a>
                                        <div class="text-center innerAll">
                                            <a href="" class="strong  ">Billing</a>
                                            <div class="clearfix"></div>
                                            <small class="text-center">(PO/PR/ใบเสร็จ)</small>
                                        </div>
                                    </div>
                                </div>
                                <div class="col-sm-3">
                                    <div class="widget">
                                        <a href="#" class="display-block bg-purple innerAll text-center text-white"><i class=" icon-graph-up-1 fa-5x"></i></a>
                                        <div class="text-center innerAll">
                                            <a href="" class="strong  ">Search/Report</a>
                                            <div class="clearfix"></div>
                                            <small class="text-center">(ค้นหา/รายงาน)</small>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- End Featured -->

                            <div class="clearfix"></div>
                        </div>
                    </div>
                </div>



            </div>
            <!-- // Content END -->

            <div class="clearfix"></div>

        </div>
        <!-- // Main Container Fluid END -->


        <!-- Global -->
        <script data-id="App.Config">
            var App = {};
            var basePath = '',
                    commonPath = 'assets/',
                    rootPath = '../',
                    DEV = false,
                    componentsPath = 'assets/components/';

            var primaryColor = '#3695d5',
                    dangerColor = '#b55151',
                    successColor = '#609450',
                    infoColor = '#4a8bc2',
                    warningColor = '#ab7a4b',
                    inverseColor = '#45484d';

            var themerPrimaryColor = primaryColor;

        </script>

        <script src = "assets/components/library/bootstrap/js/bootstrap.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/plugins/nicescroll/jquery.nicescroll.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/plugins/breakpoints/breakpoints.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/plugins/preload/pace/pace.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/plugins/preload/pace/preload.pace.init.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/core/js/animations.init.js?v=v1.0.2"></script>
        <script src="assets/components/core/js/sidebar.main.init.js?v=v1.0.2"></script>
        <script src="assets/components/core/js/sidebar.discover.init.js?v=v1.0.2"></script>
        <script src="assets/components/core/js/core.init.js?v=v1.0.2"></script>	
        <script src="assets/components/plugins/preload/pace/pace.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/plugins/preload/pace/preload.pace.init.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/common/tables/datatables/assets/lib/js/jquery.dataTables.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/common/tables/datatables/assets/lib/extras/TableTools/media/js/TableTools.min.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/common/tables/datatables/assets/custom/js/DT_bootstrap.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/common/forms/elements/fuelux-checkbox/fuelux-checkbox.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/common/forms/elements/bootstrap-select/assets/lib/js/bootstrap-select.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/common/forms/elements/bootstrap-select/assets/custom/js/bootstrap-select.init.js?v=v1.0.2&sv=v0.0.1"></script>
        <script src="assets/components/common/tables/datatables/assets/lib/extras/ColVis/media/js/ColVis.min.js?v=v1.0.2&sv=v0.0.1"></script>

        <script type="text/javascript" src="js/jquery.uploadfile.js"></script>
        <link rel="stylesheet" type="text/css" href="js/uploadfile.css" media="screen" />
        <!-- Add fancyBox main JS and CSS files -->
        <script type="text/javascript" src="js/jquery.blockUI.js"></script>
        <script type="text/javascript" src="fancy-box-lib/jquery.fancybox.js?v=2.1.5"></script>
        <link rel="stylesheet" type="text/css" href="fancy-box-lib/jquery.fancybox.css?v=2.1.5" media="screen" />

        <!-- Add Button helper (this is optional) -->
        <link rel="stylesheet" type="text/css" href="fancy-box-lib/helpers/jquery.fancybox-buttons.css?v=1.0.5" />
        <script type="text/javascript" src="fancy-box-lib/helpers/jquery.fancybox-buttons.js?v=1.0.5"></script>

        <!-- Add Thumbnail helper (this is optional) -->
        <link rel="stylesheet" type="text/css" href="fancy-box-lib/helpers/jquery.fancybox-thumbs.css?v=1.0.7" />
        <script type="text/javascript" src="fancy-box-lib/helpers/jquery.fancybox-thumbs.js?v=1.0.7"></script>

        <!-- Add Media helper (this is optional) -->
        <script type="text/javascript" src="fancy-box-lib/helpers/jquery.fancybox-media.js?v=1.0.6"></script>
        <script type="text/javascript" src="js/bootstrap-datepicker.js"></script>
        <link rel="stylesheet" type="text/css" href="js/datepicker.css" media="screen" />

        <!-- Page-Level Plugin Scripts - Tables -->
        <script src="js/jquery.dataTables.js"></script>
        <script src="js/dataTables.bootstrap.js"></script>
        <link rel="stylesheet" type="text/css" href="js/jquery.dataTables" media="screen" />

        <script type="text/javascript">
            $(document).ready(function() {
                $("#load-account-page").click(function() {
                    blockPage();
                    var dataSent = "<?= $_SESSION['username'] ?>";
                    var jqxhr = $.post("model/GetUsersData.php?username=" + dataSent);
                    jqxhr.success(function(data) {
                        //data = JSON data;
                        obj = JSON.parse(data);
                        $("#test-load").load("my_account.php?first_name=" + obj.fName + "&last_name=" + obj.lName + "&dob=" + obj.dob + "&gender=" + obj.gender + "&age=" + obj.age + "&username=" + obj.username, function() {
                            $.unblockUI();
                        });
                    });
                    jqxhr.error(function() {
                        alert("ไม่สามารถติดต่อกับ Server ได้");
                    });

                });
                $("#logout-to").click(function() {
                    var jqxhr = $.post("model/LogoutDesSession.php");
                    jqxhr.success(function(data) {
                        alert(data);
                        window.location.assign("index.php")
                    });
                    jqxhr.error(function() {
                        alert("ไม่สามารถติดต่อกับ Server ได้");
                    })
                });
                $(".link-project").click(function() {
                    blockPage();
                    $("#test-load").empty();
                    $("#test-load").load("project_tables.php", function() {
                        $.unblockUI();
                    });
                });
                $(".link-team-builder").click(function() {
                    blockPage();
                    $("#test-load").empty();
                    $("#test-load").load("TeamBuilderMainPage.php", function() {
                        $.unblockUI();
                    });
                });
                $(".link-po-inspection").click(function() {
                    $("#test-load").empty();
                    $("#test-load").load("PoInspectionMainPage.php", function() {
                        $.unblockUI();
                    });
                });
            });
            function blockPage() {
                $.blockUI({message: 'Operation in progress...', css: {
                        border: 'none',
                        padding: '15px',
                        backgroundColor: '#000',
                        '-webkit-border-radius': '10px',
                        '-moz-border-radius': '10px',
                        opacity: .5,
                        color: '#fff'
                    }});
            }
        </script>
    </body>
</html>